/***********************************************************************
 * Module:  AddState.java
 * Author:  Nikola
 * Purpose: Defines the Class AddState
 ***********************************************************************/

package genedit.controller;

import genedit.model.graph.GraphElement;
import genedit.view.graph.GraphWorkArea;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;

public class AddState extends State {
	public Creator factory;

	/** @param e */
	public void mouseReleased(MouseEvent e) {
		Point position = e.getPoint();
		context.pointToUserSpace(position);
		GraphElement newElement = factory.instantiate(new Point2D.Double(position.getX() - 30,
				position.getY() - 20), new Dimension(60, 40));

		AddCommand addCommand = new AddCommand(true);
		addCommand.getAddedElements().add(newElement);
		addCommand.setDocument(context.getView());
		context.getView().getModel().getInvoker().executeCommand(addCommand);
	}

	/** @param e */
	public void mouseDragged(MouseEvent e) {
		// TODO: implement
	}

	/** @param e */
	public void mouseClicked(MouseEvent e) {
		// TODO: implement
	}

	/** @param e */
	public void keyPressed(KeyEvent e) {
		// TODO: implement
	}

	/**
	 * @param context
	 * @param factory
	 */
	public AddState(GraphWorkArea context, Creator factory) {
		super(context);
		this.factory = factory;
	}

	/** @pdGenerated default parent getter */
	public Creator getFactory() {
		return factory;
	}

	/**
	 * @pdGenerated default parent setter
	 * @param newCreator
	 */
	public void setFactory(Creator newCreator) {
		this.factory = newCreator;
	}

}